﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Diagnostics;
using System.IO;

namespace Lilium.Data.Repository
{
	public class DataContextAdapter: IRepositoryProvider
	{
		public DataContextAdapter(DataContext dataContext)
		{
			if (dataContext == null) throw new ArgumentNullException("dataContext");

			m_DataContext = dataContext;

            dataContext.Log = new StringWriter();
		}

		#region IRepositoryProvider Members

		public IRepository<TEntity> GetRepository<TEntity>() where TEntity: class
		{
			return new TableAdapter<TEntity>(DataContext.GetTable<TEntity>());
		}

		#endregion

		#region private DataContext DataContext

		private readonly DataContext m_DataContext;

		private DataContext DataContext
		{
			[DebuggerNonUserCodeAttribute]
			get
			{
				return m_DataContext;
			}
		}

		#endregion
	}
}